package com.hfh.reflect;

/**
 * @Author hfh
 * @Date 2022 09 14 17 25
 **/
import java.lang.reflect.Field;
class SetProperty{
    public void setProperty(Object obj, String propertyName, Object value){
        try {
            Field f = obj.getClass().getDeclaredField(propertyName);
            f.setAccessible(true);
            f.set(obj,value);
        } catch (Exception e) {
            System.out.println("修改失败");
        }
    }
}
public class Work3{
    private String s = "true";
    public static void main(String[] args) {
        Work3 t = new Work3();
        SetProperty s = new SetProperty();
        s.setProperty(t, "s","false");
        System.out.println(t.s);
    }
}
